﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using WpfSnqkGasAnalysis.Model;

namespace WpfSnqkGasAnalysis 
{
    /// <summary>
    /// 小数处理保留位数
    /// </summary>
    /// 创建时间：2023-1-31 09:27:11。作者：王浩力
    internal class FloatConvert : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter">传要保留的小数位</param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return "/";
            }
            if (parameter == null)
            {
                return value;
            }
            if (int.TryParse(parameter.ToString(), out int baoliu))
            {
                string point = "f" + baoliu;
                return value.ToMyDecimal2().ToString(point);
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
